package service

import (
	"context"
	"driver_srv/basic/driverproto"
	"driver_srv/handler/dao"
	"errors"
)

type Server struct {
	__.UnimplementedDriverServer
}

// 车辆添加
func (s *Server) VehicleAdd(_ context.Context, in *__.VehicleAddReq) (*__.VehicleAddResp, error) {
	Vehicle, err := dao.VehicleAdd(in)
	if err != nil {
		return nil, errors.New("创建车辆失败" + err.Error())
	}
	return &__.VehicleAddResp{VehicleId: int64(Vehicle.Id)}, nil
}

// 车辆证件添加
func (s *Server) VehicleFilesAdd(_ context.Context, in *__.VehicleFilesAddReq) (*__.VehicleFilesAddResp, error) {
	vehicleFiles, err := dao.VehicleFilesAdd(in)
	if err != nil {
		return nil, errors.New("车辆证件添加失败" + err.Error())
	}
	return &__.VehicleFilesAddResp{VehicleFilesId: int64(vehicleFiles.Id)}, nil
}

// 网约车添加
func (s *Server) RideHailingAdd(_ context.Context, in *__.RideHailingAddReq) (*__.RideHailingAddResp, error) {
	rideHailing, err := dao.RideHailingAdd(in)
	if err != nil {
		return nil, errors.New("网约车添加失败" + err.Error())
	}
	return &__.RideHailingAddResp{RideHailingId: int64(rideHailing.Id)}, nil
}

// 车辆展示
func (s *Server) ListVehicle(_ context.Context, in *__.ListVehicleReq) (*__.ListVehicleResp, error) {
	vehicleList, err := dao.ListVehicle(in)
	if err != nil {
		return nil, errors.New("车辆查询失败" + err.Error())
	}
	return &__.ListVehicleResp{ListVehicle: vehicleList}, nil
}
